package com.yunkeji.common.enums.app;

import cn.hutool.json.JSONUtil;
import com.yunkeji.common.apply.CallOperationApply;
import com.yunkeji.common.msg.PushMessage;
import com.yunkeji.common.msg.bo.CallInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;

/** 通话操作枚举 */
@Getter
@AllArgsConstructor
public enum CallOperationEnum {
    发起呼叫(MsgTypeEnums.发起呼叫, CallOperationEnum::startCall),
    被叫振铃(MsgTypeEnums.被叫振铃, CallOperationEnum::startRinging),
    被叫接听(MsgTypeEnums.被叫接听, CallOperationEnum::startAnswer),
    主叫确认(MsgTypeEnums.主叫确认, CallOperationEnum::startComfirm),
    挂断通话(MsgTypeEnums.挂断通话, CallOperationEnum::startCancel);
    // 消息类型
    private MsgTypeEnums type;
    // 请求函数
    private CallOperationApply apply;

    /**
     * 发起呼叫
     *
     * @return
     */
    private static Boolean startCall(CallInfo callInfo) {
        return PushMessage.pushCallSignalBatch(
                callInfo.getFromPlatFormId(),
                callInfo.getToPlatFormId(),
                JSONUtil.parseObj(callInfo),
                CallOperationEnum.发起呼叫.type);
    }
    /**
     * 被叫振铃
     *
     * @return
     */
    private static Boolean startRinging(CallInfo callInfo) {
        return PushMessage.pushCallSignalBatch(
                callInfo.getFromPlatFormId(),
                callInfo.getToPlatFormId(),
                JSONUtil.parseObj(callInfo),
                CallOperationEnum.被叫振铃.type);
    }

    /**
     * 被叫接听
     *
     * @return
     */
    private static Boolean startAnswer(CallInfo callInfo) {
        return PushMessage.pushCallSignalBatch(
                callInfo.getFromPlatFormId(),
                callInfo.getToPlatFormId(),
                JSONUtil.parseObj(callInfo),
                CallOperationEnum.被叫接听.type);
    }

    /**
     * 主叫确认
     *
     * @return
     */
    private static Boolean startComfirm(CallInfo callInfo) {
        return PushMessage.pushCallSignalBatch(
                callInfo.getFromPlatFormId(),
                callInfo.getToPlatFormId(),
                JSONUtil.parseObj(callInfo),
                CallOperationEnum.主叫确认.type);
    }

    /**
     * 挂断电话
     *
     * @return
     */
    private static Boolean startCancel(CallInfo callInfo) {
        return PushMessage.pushCallSignalBatch(
                callInfo.getFromPlatFormId(),
                callInfo.getToPlatFormId(),
                JSONUtil.parseObj(callInfo),
                CallOperationEnum.挂断通话.type);
    }
}
